(function(window,undefined){
	var _cur_lat,_cur_lng;
	
	var Store = {};
	window.Store = window.Store || Store;
	
	/*page별 선언*/
	var storeViewPage = Store.storeViewPage = {};
	var storePage = Store.storePage = {};
	
	/*model > storePage > 상점이 없을떄*/
	var loadRecommendStore = function(successCallback){
		var strLandmark = sessionStorage.getItem('landmark_code');
		var strParentLM = strLandmark.substring(0,2);
		var strCategory = sessionStorage.getItem('category_code');
		
		$.ajax({
			type:'post',
			url:ajaxURL+'store.php?action=loadRecommendStore',
			data:{parent_landmark:strParentLM,category_code:strCategory},
			dataType:'json',
			success:function(result){
				successCallback(result);
			}
		});
	};
	
	storePage.recommendStoreBlock = function(){
		loadRecommendStore(function(result){
			console.log('ss');
			console.log(result);
			
			var selector0 = '#x_recommend_store_head';
			var selector1 = '#x_recommend_store_list';
			$(selector0).hide();
			
			if(result.length != 0){
				$(selector0).show();
			} else{
				return;
			}
			
			var info ='';
			info += '<h3><img src="images/titles/recommend_store.png" alt="추천스토어"/></h3>';
			// info += '<a class="right" href="#"><img src="images/btn_refresh.png" alt="btn_refresh"  /></a>';
			info += '<div class="clear height10"></div>';
			info += '<ul id="x_recommend_store_list" class="storeList unitWrap styleA"></ul>';
			
			$(selector0).html(info);
			
			$.each(result,function(key){
				template.storeList(this,selector1,key);
			});
		});
	};
	
	/*스토어뷰 페이지에 왔을때 DB에 방문자 수를 올린다.*/
	storeViewPage.addStoreView = function(){
		var store_id = getUrlId();
		var user_id = sessionStorage.getItem('user_id');
		if(!user_id){
			user_id = -1;
		}
		
		$.ajax({
			type:'post',
			url:ajaxURL+'store.php?action=addStoreView',
			data:{store_id:store_id,user_id:user_id},
			success:function(result){
				console.log('ssss');
				console.log(result);
				if(result != 'success'){
					alert('addStoreView parameter miss');
				}
			}
		});
	};
	
	Store.storeGalleryBlock = function(){
		var _store_id = getUrlId();
		var _pointer = 0;
		var _result = null;
		
		$.ajax({
			type:"post",
			url:ajaxURL+'store.php?action=loadStoreGallery',
			dataType:"json",
			data:{store_id:_store_id},
			success:function(result){
				console.log(result);
				_result = result;
				
				var info0 = '';
				$.each(result,function(key){
					info0 += '<li><a href="#"><img style="width:80px; height:80px;" data-pointer="'+key+'" src="'+this.image+'" alt="thumb_pic_s"></a></li>';
				});
				$('.galleryWidget > ul').html(info0).append('<div class="clear"></div>');
				
				/*큰 사진 init*/
				$('.imgWrap > img').css({"width":"800px","height":"600px","margin":"0px"}).attr('src',result[_pointer].image);
			
				/*큰 사진 네비 init*/
				$('.galleryNav > ul').empty();/*임시*/
				// var info1 = '<li class="arrowWrap"><a class="navArrow prev"></a></li>';
				// $.each(result,function(){
					// info1 += '<li><a><img src="'+this.image+'" alt="store_gallery_thumb_1" style="width:60px;height:60px;"></a></li>';
				// });
				// $('.galleryNav > ul').html(info1).append('<li class="arrowWrap"> <a class="navArrow next"></a></li>');
				
				/*갤러리 크게보기*/
				$('.galleryWidget > ul > li > a > img').off('click').on("click",function(event){
					event.preventDefault();
					_pointer=$(this).data('pointer');
					$('.imgWrap > img').attr('src',_result[_pointer].image);
					$('#storeGallery,.modalBg').show();
				});
			}
		});
		
		/*이전 사진 보기*/
		$('a.imgArrow.prev').off('click').on('click',function(event){
			event.preventDefault();
			
			if(_result == null){
				//ajax Recall
				return;
			}
			
			if(_pointer == 0){
				return;
			}
			
			_pointer -= 1;
			$('.imgWrap > img').fadeOut('fast',function(){
				$('.imgWrap > img').attr('src',_result[_pointer].image);
			}).fadeIn('slow');
		});
		
		/*다음 사진 보기*/
		$('a.imgArrow.next').off('click').on('click',function(event){
			event.preventDefault();
			
			if(_result == null){
				//ajax Recall
				return;
			}
			
			if(_result.length == _pointer+1){
				return;
			}
			_pointer += 1;
			$('.imgWrap > img').fadeOut('fast',function(){
				$('.imgWrap > img').attr('src',_result[_pointer].image);
			}).fadeIn('slow');
		});
		
		/*갤러리 크게보기*/
		$('#galleryBtn').off('click').on("click",function(event){
			event.preventDefault();
			if(_result.length == 0){
				alert('등록된 사진이 없습니다.');
			}else{
				$('#storeGallery,.modalBg').show();
			}
		});
		
		/*갤러리 크게보기 닫기*/
		$('.galleryClose').off('click').on("click",function(event){
			event.preventDefault();
			$('#storeGallery,.modalBg').hide();
		});
	};
	
	var storeMap = function(_latitude,_longitude,_storeName){	
		$('#showMapBtn').off('click').on("click",function(event){
			event.preventDefault();
			
			$('#storeMapModal,.modalBg').show();
			bigMapBlock(_latitude, _longitude,_storeName);
		});
		
		$('#closeMapBtn').off('click').on("click",function(event){
			event.preventDefault();
			$('#storeMapModal,.modalBg').hide();
		});
	};
	
	/*index > 신규 스토어*/
	Store.newStoreBlock = function(){
		var _landmark = sessionStorage.getItem('landmark_code');
		var _category = sessionStorage.getItem('category_code');
		
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=newStoreList",
			data:{landmark:_landmark,category:_category},
			dataType:"json",
			success:function(result){
				console.log('newStoreBlock');
				console.log(result);
	
				$('ul.storeListWidget1').empty();		
				$.each(result,function(key){
					if(!this.store_image){
						this.store_image = "images/default_store.png";
					}
					
					template.newStoreList(this,key);
				});
			}
		});
	};
	
	/*map*/
	Store.mapBlock = function(){
		
		var myLatlng = new google.maps.LatLng(__lat, __lng);
		var myOptions = {
			zoom : 9,
			center: myLatlng,
			disableDefaultUI: true,
  			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		var map = new google.maps.Map(document.getElementById("store_map") , myOptions);
		
		
		var markerOptions = {
			position : myLatlng,
			map : map,
			draggable : false
		};
		
		var store_marker = new google.maps.Marker(markerOptions);
		
		
	};
	/*index.php > 인기스토어*/
	Store.mainStoreListBlock = function(){
		loadStoreList (5,'단골 순',function(result){
			var selector = 'ul.storeList';
			$(selector).empty();
		
			if(result.dataLength == 0){			
				template.noStore(selector);
				$('.left .unitWrap.styleA').css("border","none");
			}
					
			$.each(result.data,function(key){
				$('.left .unitWrap.styleA').css("border","1px solid #ccc"); 
						
				template.mainStoreList(this,selector,key);
						
				Store.loadFavoriteUser(this.storeFavoriteUser,key,this.isFavorite);
				Store.loadPost(this.storePost,key,'main');
			});
		});
	};
	
	
	/*store.php > 인기스토어*/
	Store.storeListBlock = function(){
		storeListBlock('만족도 순');
		$('ul.headFilter > li > a:nth(0)').addClass('orange');
		var _sorting;
		
		$('ul.headFilter > li > a').off('click').on("click",function(event){
			event.preventDefault();
			Paging.initCurrentPage();
			_sorting=$(this).html();
			$('ul.headFilter > li > a').removeClass('orange');
			$(this).addClass('orange');
			storeListBlock(_sorting);	
			
		});
	};
	
	
	var storeListBlock = function(_sorting){
		loadStoreList (10,_sorting,function(result){
			var selector = '#x_store_list';
			var selector0 = '#x_recommend_store_head';
			
			$(selector).empty();
			$(selector0).hide();
			
			if(result.dataLength == 0){
				template.noStore(selector);
				$('.left .unitWrap.styleA').css("border","none");
				storePage.recommendStoreBlock();
			}
			
			$.each(result.data,function(key){
				$('.left .unitWrap.styleA').css("border","1px solid #ccc"); 
				
				template.storeList(this,selector,key);
						
				Store.loadFavoriteUser(this.storeFavoriteUser,key,this.isFavorite);
				Store.loadPost(this.storePost,key,'store');	
			});
			$('div.countWrap').html('(<b>'+result.dataLength+'</b>개)');
	
		});
	}
	
	/*mystore.php > 단골스토어*/
	Store.myStoreBlock = function(){
		var selector = 'ul.storeList';
		
		Store.loadMyStoreList(function(result){
			$(selector).empty();
			if(result.dataLength == 0){			
				template.noMyStore(selector);
				$('.left .unitWrap.styleA').css("border","none");
				return ;
			}
			
			$.each(result.data, function(key) {
				$('.left .unitWrap.styleA').css("border","1px solid #ccc"); 
				if (this.store_image == false) {
					this.store_image = 'images/default_store.png';
				}

				template.myStoreList(this, selector, key);
				if(checkUrlId()==sessionStorage.getItem('user_id')){
					Store.loadFavoriteUser(this.storeFavoriteUser, key, this.isFavorite);
				}
			});

			Store.store_listener();
			$('span.headCount > b:nth(0)').html(result.dataLength);
			var _para = {
				dataLength : result.dataLength,
				// dataLength : 1000,
				selector : '#pagination > ul',
				callback : function() {
					Store.myStoreBlock();
				}
			};

			Paging.innerAJAX(_para); 
		});
	};
	
	/*view*/
	Store.mainViewBlock = function(){
		var _store_id = getUrlId();
		var _user_id = sessionStorage.getItem('user_id');
		var _landmark = sessionStorage.getItem('landmark_code');
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=loadMainInfo",
			data:{user_id:_user_id,store_id:_store_id,landmark:_landmark},
			dataType:"json",
			success:function(result){
				console.log('mainViewBlock');
				console.log(result);
				
				/*주소창url로 바로 들어올 경우*/
				if(!_landmark){
					sessionStorage.setItem('landmark_code',result.landmark_code);
					sessionStorage.setItem('landmark_name',result.landmark_name);
				}
				myBlockPackage();
				storeMap(result.latitude, result.longitude, result.name);
				load_map(result.latitude, result.longitude);
				
				if(result.addr0 == null){
					result.addr0 = '';
				}
				if(result.addr1 == null){
					result.addr1 = '';
				}
				if(result.addr2 == null){
					result.addr2 = '';
				}
				if(result.addr3 == null){
					result.addr3 = '';
				}
				if(result.addr4 == null){
					result.addr4 = '';
				}
				
				if(result.isCoupon==true){
					result.isCoupon = '<img src="images/icon_coupon.png" alt="쿠폰">';
				} else{
					result.isCoupon = '';
				}
				
				if(!result.store_image==null || result.store_image==""){
					result.store_image = 'images/default_store.png';
				}
				
				result.address = result.addr0 + ' ' + result.addr1 + ' ' + result.addr2 + ' ' + result.addr3 + ' ' + result.addr4;
				
				template.mainViewBlock(result);
				
				Store.loadFavoriteUser(result.storeFavoriteUser,0,result.isFavorite);
				Store.store_listener();
				
			}
		});
	};
	
	var compareTime = function(_weekDayStart,_weekDayEnd,_weekendStart,_weekendEnd){
		var openStatus;
		
		var _weekDayStart = _weekDayStart.split(':');
		var _weekDayEnd = _weekDayEnd.split(':');
		
		var _weekendStart = _weekendStart.split(':');
		var _weekendEnd = _weekendEnd.split(':');
		
		var _current = new Date();
		var _currentTime =new Date('1989','01','02',_current.getHours(),_current.getMinutes(),_current.getSeconds());
		if(_currentTime.getDay()==0 || _currentTime.getDay()==6){/*주말*/
			var _weekendStart = new Date('1989','01','02',_weekendStart[0],_weekendStart[1],_weekendStart[2]);
			var _weekendEnd = new Date('1989','01','02',_weekendEnd[0],_weekendEnd[1],_weekendEnd[2]);

			if((_weekendStart-_currentTime)<=0 && (_weekendEnd-_currentTime)>=0){
				openStatus='open';
			}else{
				openStatus='close';
			}
		}else{
			var _weekDayStart = new Date('1989','01','02',_weekDayStart[0],_weekDayStart[1],_weekDayStart[2]);
			var _weekDayEnd = new Date('1989','01','02',_weekDayEnd[0],_weekDayEnd[1],_weekDayEnd[2]);

			if((_weekDayStart-_currentTime)<=0 && (_weekDayEnd-_currentTime)>=0){
				openStatus='open';
			}else{
				openStatus='close';
			}
		}
		return openStatus;
		
	};
	
	/*store_view*/
	Store.detailViewBlock = function(){
		var _store_id = getUrlId();
		// var _store_id = 1949;
		
		$('.unitWrap > table').empty();
		
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=loadDetailInfo",
			data:{store_id:_store_id},
			dataType:"json",
			success:function(result){
				console.log('detailViewBlock');
				console.log(result.data);
				console.log(result.menu);
				
				template.detailViewBlock(result.data,result.menu);
			}
		});
	}; 
	
	/*model > store.php > store_list*/
	var loadStoreList = function(_to,_sorting,callback){
		var _landmark_code = sessionStorage.getItem('landmark_code');
		var _category= sessionStorage.getItem('category_code');
		var _user_id = sessionStorage.getItem('user_id');
		
		if(_landmark_code == null){
			_landmark_code = 'GGSNMR';
		}
		if(!_category){
			_category = DEFAULT_CATEGORY;
		}
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=loadStoreList",
			data:{user_id:_user_id,landmark:_landmark_code,category:_category,sorting:_sorting,row:Paging.getCurrent(),to:_to},
			dataType:"json",
			success:function(result){
				console.log('storeList');
				console.log(result);
				callback(result);
				Store.store_listener();
				var _para = {
					dataLength : result.dataLength,
					// dataLength : 1000,
					selector : '#pagination > ul',
					callback : function(){
						Store.storeListBlock();
					}
				};
						
				Paging.innerAJAX(_para);
			}
		})
	};
	
	                                  
	/*store.php > 단골 추가*/
	var addFavoriteStore = function(_store_id,successCallback){
		var _user_id = sessionStorage.getItem('user_id');
		
		if(!_user_id){
			if(confirm('본 기능은 로그인이 필요한 기능입니다. 로그인하러 가시겠습니까?')){
				location.href='login.php';
			}
			return ;	
		}
		
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=addFavoriteStore",
			data:{user_id:_user_id,store_id:_store_id},
			success:function(result){
				console.log("addFavoriteStore");
				console.log(result);
				if(result=='success'){
					alert(SUCCESS_INSERT_FAVORITE);
					successCallback();
				}else if(result=='fail'){
					alert(FAIL_INSERT_FAVORITE);
				}
				
				
			}
		});
	};
	
	/*store.php > 단골 해제*/
	var delFavoriteStore = function(_store_id,successCallback){
		var _user_id = sessionStorage.getItem('user_id');
		
		if(!_user_id){
			if(confirm('본 기능은 로그인이 필요한 기능입니다. 로그인하러 가시겠습니까?')){
				location.href='login.php';
			}
			return ;	
		}
		
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=delFavoriteStore",
			data:{user_id:_user_id,store_id:_store_id},
			success:function(result){
				console.log("addFavoriteStore");
				console.log(result);
				if(result=='success'){
					alert(SUCCESS_DELETE_FAVORITE);
					successCallback();
				}else if(result=='fail'){
					alert(FAIL_DELETE_FAVORITE);
				}
				
				
			}
		});
	};
	Store.store_listener = function(){
		/*단골 등록, 해제*/
		$(".btnDangol.on,.btnDangol.off").off('click').on("click",function(event){
			event.preventDefault();
			var that = this;
			
		    var _store_id=$(this).parent().data('store_id');
		    if( $(this).is(".on") ) {
		        addFavoriteStore(_store_id,function(){
		        	 $(that).toggleClass("on off");
		        });
		    }
		    else {
		        delFavoriteStore(_store_id,function(){
		        	 $(that).toggleClass("on off");
		        });
		    }    
		   
		});
		
		/*상점보기 페이지 링크*/
		$('.storeList .thumbWrap a,.storeList .title').off('click').on('click', function(event) {
			event.preventDefault();
			var _store_id=$(this).data('store_id');
			location.href='store_view.php?id='+_store_id;
		});
	};
	
	/*나의 단골 스토어*/
	Store.loadMyStoreList = function(callback){
		var _user_id = checkUrlId();
		
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=loadMyStoreList",
			dataType : "json",
			data:{user_id:_user_id,row:Paging.getCurrent()},
			success:function(result){
				console.log("loadMyStoreList");
				console.log(result);
				callback(result);
			}
		});
	};
	
	/*store_view.php > 상점상세페이지*/
	var storeInformation = function(_store_id){
			
		$.ajax({
			type:"post",
			url:ajaxURL+"store.php?action=mainInformation",
			dataType : "json",
			data:{store_id:_store_id},
			success:function(result){
				console.log("storeInformation");
				console.log(result);
			}
		});
	};
	
	/*스토어리스트에 스토어를 단골로 등록한 사람들의 사진들*/
	Store.loadFavoriteUser = function(result,key,isFavorite) {

				
		var info = '';
		$.each(result,function(){
			if(this.user_image==null || this.user_image==""){
				this.user_image = "images/default_user.png";
			}
			info += '<a href="people_view.php?id='+this.user_id+'"><img src="'+this.user_image+'"></a>';
			
		});
		
		if(isFavorite==true){
			$('.friends:nth('+key+')').append(info+'<a href="#" class="btnDangol off">단골 해제</a>');
		} else if(isFavorite==false){
			$('.friends:nth('+key+')').append(info+'<a href="#" class="btnDangol on">단골 추가</a>');
		}
	};
	
	/*스토어리스트의 각 상점에 써진 글들*/
	Store.loadPost = function(result,key,position) {
		if(result.length==0){
			$('.commentWrap:nth('+key+')').append('등록된 토크가 없습니다.');
		}
		var info = '';
		$.each(result,function(key2){
			if(this.message.length>=61){
				this.message = this.message.substr(0,61)+" ...";
			}
			if(position=='main'){
				if(key==0){
					info += '<a data-post_id="'+this.post_id+'" class="add" href="#"><span>'+this.user_name+'</span> - '+this.message+' </a></br>';
					
				}else if(key!=0 && key2==0){
					info += '<a data-post_id="'+this.post_id+'" class="add" href="#"><span>'+this.user_name+'</span> - '+this.message+' </a></br>';
		
				}
	
			}else if (position=='store'){
			
				if(key2==0){
					info += '<a data-post_id="'+this.post_id+'" class="add" href="#"><span>'+this.user_name+'</span> - '+this.message+' </a></br>';
		
				}
			}
		});
		
		
		$('.commentWrap:nth('+key+')').append(info);

	};
	
	
	var load_map = function(_lat, _lng) {
		var element = "map_canvas";
	    var map;
	    
	    var latlng = new google.maps.LatLng(_lat, _lng);
    	var myOptions = {
    		scrollwheel : false,
			zoom : 16,
			center : latlng,
			mapTypeId : google.maps.MapTypeId.ROADMAP,
			panControl : false,
			zoomControl : false,
			scaleControl : false,
			streetViewControl : false,
			overviewMapControl : false,
			mapTypeControl : false,
			zoomControlOptions : { style : google.maps.ZoomControlStyle.LARGE,
				position :
				google.maps.ControlPosition.LEFT_CENTER
			}
    	};
    
	    map = new google.maps.Map(document.getElementById(element), myOptions);
	    var markerOptions = {
	    	position:latlng,
	        map:map,
	        draggable:false,
	        icon:'images/black_icon.png'
   		};
    	var marker = new google.maps.Marker(markerOptions);
	};
	
	var bigMapBlock = function(_lat, _lng, _storeName) {
		var element = "map_canvas2";
	    var _store_map;
	    
	    var latlng = new google.maps.LatLng(_lat, _lng);
		var myOptions = {
				zoom : 15,
				center : latlng,
				mapTypeId : google.maps.MapTypeId.ROADMAP,
				panControl : false,
				zoomControl : true,
				scaleControl : false,
				streetViewControl : false,
				overviewMapControl : false,
				mapTypeControl : false
		};
	
		_store_map = new google.maps.Map(document.getElementById(element), myOptions);
		var markerOptions = {
			position : latlng,
			map : _store_map,
			draggable : false,
			animation : google.maps.Animation.DROP,
			icon:'images/black_icon.png'
	
		};
	
		var mylatlng = new google.maps.LatLng(_cur_lat, _cur_lng);
	
		var mymarkerOptions = {
			position : mylatlng,
			map : _store_map,
			draggable : false,
			animation : google.maps.Animation.BOUNCE,
			icon:'images/green_icon.png'
	
		};
	
		_store_marker = new google.maps.Marker(markerOptions);
	
		var infoBubble2 = new InfoBubble({
			content : '<div class="phoneytext">' + _storeName + '</div>',
			minWidth : 200,
			maxWidth : 300,
			minHeight : 60,
			maxHeight : 60,
			shadowStyle : 1,
			padding : 0,
			backgroundColor : 'rgb(57,57,57)',
			borderRadius : 4,
			arrowSize : 10,
			borderWidth : 1,
			borderColor : '#2c2c2c',
			disableAutoPan : true,
			hideCloseButton : true,
			arrowPosition : 50,
			backgroundClassName : 'phoney',
			arrowStyle : 0
	
		});
	
		infoBubble2.open(_store_map, _store_marker);
	
	
		my_marker = new google.maps.Marker(mymarkerOptions);
		googleApi2.init();
		
		$('#current_lo').click(function() {
			var mylatlng = new google.maps.LatLng(_cur_lat, _cur_lng);
			_store_map.panTo(mylatlng);
			my_marker.setPosition(mylatlng);
	
		});
		$('#store_lo').click(function() {
			var mylatlng = new google.maps.LatLng(_lat, _lng);
			_store_map.panTo(mylatlng);
		});
	};
	
	var googleApi2 = {
		init : function() {
			if (!navigator.geolocation) {
				alert(FAIL_GEOLOCATOIN); 
				return; 
			}
			navigator.geolocation.getCurrentPosition(this.successCallback, this.errorCallback);
		},

		successCallback : function(position) {
			_cur_lat = position.coords.latitude;
			_cur_lng = position.coords.longitude;
			console.log(_cur_lat);
		},

		errorCallback : function(error) {
			alert(FAIL_GOOGLE_API);
		}
	}; 

	
	/*store template*/
	var template = {
		noStore : function(selector){
			var category_name;
			($('.depth2 .menu .on a').html()=='전체')?category_name=$('.depth1 .menu .on a').html():category_name=$('.depth2 .menu .on a').html().substring(0,$('.depth2 .menu .on a').html().length-3);
		
			var info='';
			info+='<div  class="noneListWrap">';
    		info+='<div style="border:none;" class="titleArea">';
	    	info+='<img src="images/nolist_store.png" alt="nolist_store"  />';
    		info+='<h4><span>'+sessionStorage.getItem('landmark_name')+'</span>에는 <span>'+ category_name+'</span>에 해당하는 스토어가 없습니다.<br/></h4>';
    		info+='</div>';
    		info+='<div class="subArea">';
    		info+='<p>고객님이 알고 계시는 상점을 추천해 주세요.<br/>아니면 사장님이실 경우 가게를 등록해 주세요.<br/>가맹문의 : 02) 155 - 2276<br/><br/>';				
			info+='<a href="#"><img src="images/btn_reg.png" alt="등록하기"/></a>';
    		info+='</p></div>';
    		info+='</div>';
    		$(selector).append(info);
		},
		recommendedStore : function(selector){
			
		},
		noStoreplus : function(selector){
			var info = '';
			info += '<h3><img src="images/titles/recommend_store.png" alt="추천스토어"/></h3>';
			info += '<a class="right" href="#"><img src="images/btn_refresh.png" alt="btn_refresh"  /></a>';
			info +=	'<div class="clear height10"></div>';
		},
		noMyStore : function(selector){
			var info = '';
			info += '<div class="noneListWrap">';
			info += '<div class="titleArea"><img src="images/nolist_store.png" alt="nolist_store"  />';
			info += '<h4>등록된 단골 스토어가 없습니다.';
			info += '</h4></div>';
			if(checkUrlId()==sessionStorage.getItem('user_id')){
				info += '<div class="subArea">';
				info += '<p>나만의 단골 스토어를 관리해보세요.<br/><br/>'
				info += '<a href="store.php"><img src="images/btn_link.png" alt="바로가기" /></a></p>';
				info+='</div>';
			}
			info+='</div>';
			
			$(selector).append(info);
		},
		/*index.php*/
		mainStoreList : function(result,selector,key){
			
			if (result.store_image == false) {
				result.store_image = 'images/default_store.png';
			}

			if (result.isCoupon == true) {
				result.name = result.name + ' <img src="images/icon_coupon.png" alt="쿠폰">';
			}

			var info='';
			if(key==0){
				info += '<li class="first-child bestStore" ><div class="thumbWrap">';
				info += '<a data-store_id="'+result.store_id+'" href="store.php">';
				info += '<img src="'+result.store_image+'" width="280px" height="210px"  alt="thumb_store_1" />';
				info += '</a>'	;
				info += '</div>';
				info += '<span class="ranking rank1">'+(key+1)+'</span>';
			}else{
				info += '<li '+key+'><div class="thumbWrap">';
				info += '<a data-store_id="'+result.store_id+'" href="store.php">';
				info += '<img src="'+result.store_image+'" width="160px" height="120px" alt="thumb_store_1" />';

				info += '</a>'	;
				info += '</div>';
				info += '<span class="ranking">'+(key+1)+'</span>';
			}
			info += '<div class="infoWrap">';	
			info += '<a data-store_id="'+result.store_id+'" class="title" href="store.php">'+result.name+' </a>'	;		 
			info += '<div class="tags">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';
			info += '<div class="values">만족도 <b>'+result.satisfaction+'%</b>&nbsp;&nbsp;&nbsp;&nbsp;구피토크 <b>'+result.talk_count+'</b>개</div>';
            
            info += '<div data-store_id="'+result.store_id+'" class="friends">';
            info += '</div>';
             
            info += '<div class="favorites">';
            info += '<span class="weekly"> <b>'+result.favoriteCountInWeek+'</b>명</span><br>';
            info += '<span class="total"> <b>'+result.favorite_count+'</b>명</span>';
            info += '</div></div>';

         	info += '<div class="commentWrap">';
           	info += '</div></li>';
			$(selector).append(info);
		},
		/*store.php*/
		storeList : function(result,selector,key){
			
			if (result.store_image == false) {
				result.store_image = 'images/default_store.png';
			}

			if (result.isCoupon == true) {
				result.name = result.name + ' <img src="images/icon_coupon.png" alt="쿠폰">';
			}

			var info = '';
			if(key == 0){
				info += '<li class="first-child">';
			} else {
				info += '<li>';
			}
            info += '<div class="thumbWrap">';
            info += '<a data-store_id="'+result.store_id+'" href="#">';
            info += '<img src="'+result.store_image+'" width="160px" height="120px" alt="thumb_store_etc">';
            info += '</a>';    
            info += '</div>';  
            if((Paging.getCurrent()+key)==0){   
            	info += '<span class="ranking rank1">'+(Paging.getCurrent()+key+1)+'</span>';  
            }else{
            	info += '<span class="ranking">'+(Paging.getCurrent()+key+1)+'</span>'; 
            }                                                        
            info += '<div class="infoWrap">';                     
            info += '<a data-store_id="'+result.store_id+'" class="title" href="#">'+result.name+'</a>';                         
            info += '<div class="tags">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';                     
            info += '<div class="values">';
            info += '만족도 <b>'+result.satisfaction+'%</b>&nbsp;&nbsp;&nbsp;&nbsp;리뷰 <b>'+result.talk_count+'</b>개';
            info += '</div>';                         
            info += '<div id="friends" data-store_id="'+result.store_id+'" class="friends">';
            info += '</div>';                         
            info += '<div class="favorites">';
            info += '<span class="weekly"> <b>'+result.favoriteCountInWeek+'</b>명</span><br>';
            info += '<span class="total"> <b>'+result.favorite_count+'</b>명</span><br>';
            info += '</div>';                      
            info += '</div>';                              
            info += '<div class="commentWrap">';
           	info += '</div></li>';
	
			$(selector).append(info);
		},	
		myStoreList : function(result,selector,key){
			console.log(key);
			var info = '';
			if(key == 0){
				info += '<li class="first-child">';
			} else {
				info += '<li>';
			}
            info += '<div class="thumbWrap">';
            info += '<a data-store_id="'+result.store_id+'" href="#">';
            info += '<img src="'+result.store_image+'" width="160px" height="120px" alt="thumb_store_etc">';
            info += '</a>';    
            info += '</div>';                                                               
            info += '<div class="infoWrap">';                     
            info += '<a data-store_id="'+result.store_id+'" class="title" href="#">'+result.name+'</a>';                         
            info += '<div class="tags">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';                     
            info += '<div class="values">';
            info += '만족도 <b>'+result.satisfaction+'%</b>&nbsp;&nbsp;&nbsp;&nbsp;리뷰 <b>'+result.talk_count+'</b>개';
            info += '</div>';                         
            info += '<div id="friends" data-store_id="'+result.store_id+'" class="friends">';
            info += '</div>';                         
            info += '<div class="favorites">';
            info += '<span class="weekly"> <b>'+result.favoriteCountInWeek+'</b>명</span><br>';
            info += '<span class="total"> <b>'+result.favorite_count+'</b>명</span><br>';
            info += '</div>';                      
            info += '</div>';                              
            info += "</li>";
	
			$(selector).append(info);
		},
		mainViewBlock : function(result){ 
			var info='';
			// info += '<div class="storeFlag rank"><span>12</span></div>';	     	
		    // info += '<div class="storeFlag coupon"><span>'+result.storeCouponCount+'</span></div>';
		    if(compareTime(result.weekday_start,result.weekday_end,result.weekend_start,result.weekend_end)=='open'){
		    	 info += '<div class="openClose open"></div>';
		    }else{
		    	 info += '<div class="openClose close"></div>';
		    }
		   
		    info += ' <div class="thumbWrap">';
		    info += '<a href="store_view.php">';
		    info += '<img src="'+result.store_image+'" width="300px" height="240px" alt="thumb_store_1">'
		    info += '</a>';     
		    info += '</div>';
		    info += '<div class="infoWrap">';
		    info += '<a class="title" href="store_view.php">'+result.name+' '+result.isCoupon+'</a>';
		    info += '<div class="tags">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';
			info += '<div class="values">';
			info += '만족도 <b>' + result.satisfaction + '%</b>&nbsp;&nbsp;&nbsp;&nbsp;토크 <b>'+result.talk_count+'</b>개';
			info += '</div>';
		    info += '<a id="storeShareBtn" class="shareBtn">공유하기</a>';
		    info += '<div class="extraInfo">';
		    if(sessionStorage.getItem('owner_store_id') && sessionStorage.getItem('owner_store_id')==result.store_id){
		    	info += '<div class="editBtnWrap">';
		    	info += '<a href="seller_store.php?id='+result.store_id+'" class="editBtn2">수정하기</a>';
		    	info += '</div>';
		    }
		    info += '<table><tr>';
		    info += '<th>전화번호</th><td>'+result.telephone+'</td></tr>';
		    info += '<tr><th>주소</th><td>'+result.address+'</td></tr>';
		    info += '<tr><th>시간</th><td>평일 '+result.weekday_start+' ~ '+result.weekday_end+'<br/>주말 '+result.weekend_start+' ~ '+result.weekend_end+'</td></tr>';
		    info += '</table>';
		    info += '</div>';
		    info += '<div data-store_id="'+result.store_id+'" id="friends" class="friends">';
            info += '</div>';  
			info += '<div class="favorites">';
		    info += '<span class="weekly"> <b>'+result.favoriteCountInWeek+'</b>명</span><br>';
            info += '<span class="total"> <b>'+result.favorite_count+'</b>명</span>';
		    info += '</div></div>';
		    info += '<div class="clear"></div>';
			
			$('ul.storeView li.first-child').html(info);
		},
		detailViewBlock : function(result,menu){
			if(!result.description){
				result.description = "등록된 정보가 없습니다."
			}
			
			if (result.is_credit_card == 1) {
				result.is_credit_card = '<span class="c">카드가능</span>';
			} else {
				result.is_credit_card = '';
			}
			if (result.is_booking == 1) {
				result.is_booking = '<span class="r">예약가능</span>';
			} else {
				result.is_booking = '';
			}
			if (result.is_groups == 1) {
				result.is_groups = '<span class="g">단체가능</span>';
			} else {
				result.is_groups = '';
			}
			if (result.is_parking == 1) {
				result.is_parking = '<span class="p">주차가능</span>';
			} else {
				result.is_parking = '';
			}
// 
			if (result.is_delivery == 1) {
				result.is_delivery = '<span class="d">배달가능</span>';
			} else {
				result.is_delivery = '';
			}
			
			if(result.is_credit_card == 0 && result.is_booking == 0 && result.is_groups == 0 && result.is_parking == 0 && result.is_delivery == 0){
				result.is_delivery = "등록된 정보가 없습니다.";
			}

			var info = '';
			info += '<table>';
			info += '<tr><th  width="80">이용 정보</th><td class="useInfo">';
			info += result.is_credit_card;
			info += result.is_booking;
			info += result.is_groups;
			info += result.is_parking;
			info += result.is_delivery;
			info += '</td></tr>';
			info += '<tr>';
			info += '<th>메뉴</th><td>';
			
			if(menu.length == 0){
				info += "등록된 상품이 없습니다.";
			}else {
				$.each(menu,function(){
					info += this.menu + ' ' + this.price + '원<br/>';
				});
			}
			
			info += '</td></tr>';
			info += '<tr>';
			info += '<th>소개</th><td style="width:548px;">'+result.description;
			info += '</tr>';
			info += '</table>';
			
			//info += '<tr>';
			//info += '<th>오시는 길</th>';
			//info += '<td>내용</td>';
			//info += '</tr>';
			
			$('.storeInfoWrap').html(info);
		},
		newStoreList: function(result,key){
			var info = '';
			if(key == 0){
				info += '<li class="first-child">';
			} else {
				info += '<li>';
			}
			info +=	'<div class="thumbWrap">';
			info +=	'<a href="store_view.php?id='+result.store_id+'">';
			info +=	'<img src="'+result.store_image+'" alt="thumb_store_1" style="width:160px;height:120px;">';
			info +=	'</a>';
			info +=	'</div>';
			info +=	'<div class="infoWrap">';
			info +=	'<a class="title" href="store_view.php?id='+result.store_id+'">'+result.name;
			if(result.isCoupon){
				info += ' <img src="images/icon_coupon_s.png" alt="쿠폰">';
			}
			info += '</a>'
			info +=	'<div class="tags left">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';
			info +=	'</div>';
			info +=	'</li>';
			
			$('ul.storeListWidget1').append(info);		
		}
	};
})(window);
